<?php

namespace app\models;

use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "tb_user".
 *
 * @property integer $id
 * @property string $regname
 * @property string $regrealname
 * @property string $regpwd
 * @property string $regbirthday
 * @property string $regemail
 * @property integer $regcity
 * @property integer $regcityparent
 * @property string $regico
 * @property string $regsex
 * @property string $regqq
 * @property string $reghomepage
 * @property string $regmobile
 * @property string $regintroduce
 * @property string $ip
 * @property integer $fig
 * @property integer $count
 */
class TbUser extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'tb_user';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['regbirthday'], 'safe'],
            [['regcity', 'regcityparent', 'fig', 'count'], 'integer'],
            [['regname', 'regrealname', 'regintroduce', 'ip'], 'string', 'max' => 20],
            [['regpwd', 'regemail', 'reghomepage'], 'string', 'max' => 100],
            [['regico'], 'string', 'max' => 50],
            [['regsex'], 'string', 'max' => 10],
            [['regqq'], 'string', 'max' => 40],
            [['regmobile'], 'string', 'max' => 200],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'regname' => Yii::t('app', '用户账号'),
            'regrealname' => Yii::t('app', 'Regrealname'),
            'regpwd' => Yii::t('app', 'Regpwd'),
            'regbirthday' => Yii::t('app', 'Regbirthday'),
            'regemail' => Yii::t('app', 'Regemail'),
            'regcity' => Yii::t('app', 'Regcity'),
            'regcityparent' => Yii::t('app', 'Regcityparent'),
            'regico' => Yii::t('app', 'Regico'),
            'regsex' => Yii::t('app', 'Regsex'),
            'regqq' => Yii::t('app', 'Regqq'),
            'reghomepage' => Yii::t('app', 'Reghomepage'),
            'regmobile' => Yii::t('app', 'Regmobile'),
            'regintroduce' => Yii::t('app', 'Regintroduce'),
            'ip' => Yii::t('app', 'Ip'),
            'fig' => Yii::t('app', 'Fig'),
            'count' => Yii::t('app', 'Count'),
        ];
    }

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @param int $id
     */
    public function setId($id)
    {
        $this->id = $id;
    }
    //查询前10名人
    public static function ToptenCelebrity(){
        $sql="select * from tb_user  order by count desc limit 10 ";
        $r=TbUser::findBySql($sql)->all();
        return $r;
    }
    //根据账号密码查询
    public static function Login($name){
        $r=self::find()->where(["regname"=>$name])->one();
//        $sql="select *from tb_user where regname='$name' and regpwd='$pwd'";
//        $r=TbUser::findBySql($sql)->all();
        return $r;
    }
    //根据id查询
    public function selectid($id){
        $one=self::findOne($id);
        return $one;
    }
    //根据账号查询
    public static function selectRegname($regname){
        $one=self::find()->where(["regname"=>$regname])->asArray()->one();
        return $one;
    }

    /**
     * *
     * $attributes 代表是要修改的字段的集合。
     * $condition 代表条件。
     * $params 传入的值。
     */
    public static function updateInformation($attributes,$params){
        return self::updateAll($attributes,'regname=:regname',$params);
    }

}